﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebSite.Models.NormalBudgetUploadModel>" %>

<%@ Import Namespace="WebSite.Models" %>
<%@ Import Namespace="WebSite.App_Code" %>
<%@ Import Namespace="WebSite.App_Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	NormalBudgetUpload
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <link href="../../Scripts/jquery-ui/css/redmond/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../../Scripts/jquery-ui/js/jquery-ui-1.9.2.custom.min.js"></script>
    
    <script type="text/javascript" src="../../Scripts/jquery-pending/jquery-pending.js"></script>

    <link href="../../Style/budget.01.css" rel="stylesheet">

    <style type="text/css">
    
    .List
    {
         background-color:Black;
    }
        
    .List td
    {
        background-color:White;
        white-space:nowrap;
        padding:10px;
    }
    
    </style>

    <script type="text/javascript">

        $(document).ready(function () {

            if ('<%=ViewData.ContainsKey("DB.Operation.Result") %>' == "True")
                alert('<%=ViewData["DB.Operation.Result"] %>');            
			
			<% if (Session["Budget.Data.Review"] != null || ViewData["Budget.Data.Review"] != null) { %>
				$(function () {
					$("#dialog-UploadReview").dialog({
						height: 500,
						width: 800,
						modal: true
					});
				});
			<% } %>

        });

        function openUploadWin() {
            $(function () {
                $("#dialog-UploadTemplate").dialog({
                    height: 240,
                    width: 500,
                    modal: true
                });
            });
        }

        function SelectOneBudget(sender, pc) {

            var tb = $(sender).parents("table:eq(0)");
            var checkbox = $("input[type=checkbox][IsAll=0]:checked", tb);

            var ids = "";

            for (var i = 0; i < checkbox.length; i++) {
                ids = ids + checkbox.eq(i).attr("BudgetId") + ",";
            }

            $("#Budget_ProCategory_" + pc +  "_ID_List").val(ids);
        }

        function SelectAllBudget(sender, pc) {

            var tb = $(sender).parents("table:eq(0)");
            var checkbox = $("input[type=checkbox][IsAll=0]", tb);

            for (var i = 0; i < checkbox.length; i++) {
                checkbox[i].checked = sender.checked;
            }

            SelectOneBudget(sender, pc);
        }

        function Pending(on_off) {

            if (on_off) {

                $("#dialog-Wait").pending({
                    height: 30,
                    width: 24,
                    modal: true
                });
            }
            else {

                $("#dialog-Wait").pending(false);
            }
        }

    </script>

	

    <% 
        List<BudgetItem> lsBudgetItem = new List<BudgetItem>();

        if (ViewData["Budget.DepartmentBudgetUpload.BudgetList"] != null)
            lsBudgetItem = (List<BudgetItem>)ViewData["Budget.DepartmentBudgetUpload.BudgetList"];

        List<BudgetItem> lsBudgetItem_JJ = new List<BudgetItem>();
        List<BudgetItem> lsBudgetItem_JW = new List<BudgetItem>();

        //lsBudgetItem_JJ = lsBudgetItem;
        //lsBudgetItem_JW = lsBudgetItem;

        if (lsBudgetItem.Where(o => o.Project.Project.ProjectCategoryID == "4" && o.Project.Project.ProjectTypeID == "JJ").Any())
            lsBudgetItem_JJ = lsBudgetItem.Where(o => o.Project.Project.ProjectCategoryID == "4" && o.Project.Project.ProjectTypeID == "JJ").ToList();

        if (lsBudgetItem.Where(o => o.Project.Project.ProjectCategoryID == "4" && o.Project.Project.ProjectTypeID == "JW").Any())
            lsBudgetItem_JW = lsBudgetItem.Where(o => o.Project.Project.ProjectCategoryID == "4" && o.Project.Project.ProjectTypeID == "JW").ToList();
        
    %>
    <table>
        <tr>
            <td><b>年度：<%=Model.CurrentYear %></b></td>
            <td><input type="button" value="提交" onclick="openUploadWin()" class="budget-button-no-01"/></td>
        </tr>
    </table>
    
    <br />

    <table>
        <tr>
            <td><b>已提交建设费</b></td>
            <td>
                <%if (lsBudgetItem_JJ.Count > 0)
                  { %>
                    <% using (Html.BeginForm("DepartmentBudgetUpload_DownloadTemplate", "Budget", new { id = "JJ" }))
                       { %>
                        <input type="submit" value="下载预算模板" class="budget-button-no-01" />
                        <input type="hidden" name="BudgetList" id="Budget_ProCategory_1_ID_List" />
                    <% } %>
                <% } %>
            </td>
            <td>
                <% using (Html.BeginForm("DepartmentBudgetUpload_DownloadEmptyTemplate", "Budget", new { id = "JJ" }))
                   { %>
                    <input type="submit" value="下载空白预算模板" class="budget-button-no-01" />
                <% } %>
            </td>
        </tr>
    </table>

    <table border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
        <thead>
        <tr>
            <td><input type="checkbox" IsAll="1" onclick="SelectAllBudget(this, 1)"/></td>
            <td>编制单位</td>
            <td>项目名称</td>
            <td>项目代号</td>
            <td>项目周期-起</td>
            <td>项目周期-止</td>
            <td>年度进度</td>
            <td>项目负责人</td>
            <td>状态</td>
            <td class="last"></td>
        </tr>
        </thead>
        <tbody>
        <% foreach (BudgetItem One in lsBudgetItem_JJ)
           { %>
            <tr>
                <td>
                    <input type="checkbox" onclick="SelectOneBudget(this, 1)" IsAll="0" BudgetId="<%=One.Budget.Guid %>" />
                </td>
                <td><%=One.Project.Department.DepartmentName %></td>
                <td><a style="color:Blue; text-decoration:underline; cursor:pointer" onclick="OpenBudegt('<%=One.Budget.Guid %>', 'false', '')" ><%=One.Project.Project.ProjectName %></a></td>
                <td><%=One.Project.Project.ProjectCode %></td>
                <td><%=One.Project.Project.ProjectBeginTime %></td>
                <td><%=One.Project.Project.ProjectEndTime %></td>
                <td><%=One.Budget.AnnualProgress %></td>
                <td><%=One.Project.ProjcetPIC.UserName %></td>
                <td><%=One.BS.Name %></td>
                <td>
                    <% if (Model.U.AppCan(L_ActionType.Delete
                               , new list_ProjectCategory() { ID = One.Project.ProjectCategory.ID }
                               , new md_Department() { Guid = One.Project.Department.Guid }
                               , new md_User() { Guid = One.Project.ProjcetPIC.Guid }
                               , new list_BudgetStatus() { Status = One.Budget.BudgetStatus }))
                           { %>
                            <% using (Html.BeginForm("DepartmentBudgetUpload_Delete", "Budget", new { id = One.Budget.Guid }))
                                { %>
                            <input type="submit" name="DeleteBudget" id="Submit2" value="删除" class="budget-button-no-01" onclick="return confirm('确定要删除项目代号“<%=One.Project.Project.ProjectCode %>”的预算吗？')"/>
                        <% } %>                       
                    <% } %>
                </td>
            </tr>
        <% } %>
        </tbody>
    </table>

    <br /><br />

    <table>
        <tr>
            <td><b>已提交维护费</b></td>
            <td>
                <%if (lsBudgetItem_JW.Count > 0) { %>
                    <% using (Html.BeginForm("DepartmentBudgetUpload_DownloadTemplate", "Budget", new { id = "JW" }))
                       { %>
                        <input type="submit" value="下载预算模板" class="budget-button-no-01" />
                        <input type="hidden" name="BudgetList" id="Budget_ProCategory_2_ID_List" />
                    <% } %>
                <% } %>
            </td>
            <td>
                <% using (Html.BeginForm("DepartmentBudgetUpload_DownloadEmptyTemplate", "Budget", new { id = "JW" }))
                   { %>
                    <input type="submit" value="下载空白预算模板" class="budget-button-no-01" />
                <% } %>
            </td>
        </tr>
    </table>

    <table border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
        <thead>
        <tr>
            <td><input type="checkbox" IsAll="1" onclick="SelectAllBudget(this, 2)"/></td>
            <td>编制单位</td>
            <td>项目名称</td>
            <td>项目代号</td>
            <td>项目周期-起</td>
            <td>项目周期-止</td>
            <td>年度进度</td>
            <td>项目负责人</td>
            <td>状态</td>
            <td class="last"></td>
        </tr>
        </thead>
        <tbody>
        <% foreach (BudgetItem One in lsBudgetItem_JW)
           { %>
            <tr>
                <td>
                    <input type="checkbox" onclick="SelectOneBudget(this, 2)" IsAll="0" BudgetId="<%=One.Budget.Guid %>" />
                </td>
                <td><%=One.Project.Department.DepartmentName%></td>
                <td><a style="color:Blue; text-decoration:underline; cursor:pointer" onclick="OpenBudegt('<%=One.Budget.Guid %>', 'false', '')" ><%=One.Project.Project.ProjectName %></a></td>
                <td><%=One.Project.Project.ProjectCode%></td>
                <td><%=One.Project.Project.ProjectBeginTime%></td>
                <td><%=One.Project.Project.ProjectEndTime%></td>
                <td><%=One.Budget.AnnualProgress%></td>
                <td><%=One.Project.ProjcetPIC.UserName%></td>
                <td><%=One.BS.Name %></td>
                <td>
                    <% if (Model.U.AppCan(L_ActionType.Delete
                               , new list_ProjectCategory() { ID = One.Project.ProjectCategory.ID }
                               , new md_Department() { Guid = One.Project.Department.Guid }
                               , new md_User() { Guid = One.Project.ProjcetPIC.Guid }
                               , new list_BudgetStatus() { Status = One.Budget.BudgetStatus }))
                           { %>
                            <% using (Html.BeginForm("DepartmentBudgetUpload_Delete", "Budget", new { id = One.Budget.Guid }))
                                { %>
                            <input type="submit" name="DeleteBudget" id="Submit1" value="删除" class="budget-button-no-01" onclick="return confirm('确定要删除项目代号“<%=One.Project.Project.ProjectCode %>”的预算吗？')"/>
                        <% } %>                       
                    <% } %>
                </td>
            </tr>
            </tbody>
        <% } %>
    </table>

    <div id="dialog-UploadTemplate" title="模板提交" style=" display:none">
        <table border="0" cellpadding="0" cellspacing="0" style=" width:100%" >
            <tr>
                <td colspan="4" style=" font-size:large; text-align:center; padding:10px 0px 5px 0px">
                    该页面仅用于提交机关费预算，<br />
                    非机关费预算请使用【一般预算提交】页面提交
                </td>
            </tr>
            <tr>
                <td style=" width:50px"></td>
                <td style="color:Red;">
                    注意：
                </td>
                <td style="color:Red; ">
                    1. 每次只能上传一个文件                    
                </td>
                <td style=" width:50px"></td>
            </tr>
            <tr>
                <td style=" width:50px"></td>
                <td></td>
                <td style="color:Red;">
                    2.每个文件中可以包含多个预算，但必须为同一个预算类别
                </td>
                <td style=" width:50px"></td>
            </tr>
            <tr>
                <td colspan="4" align="center" style=" padding:40px 0px 0px 0px">
                    <% using (Html.BeginForm("DepartmentBudgetUpload_Upload", "Budget", FormMethod.Post, new { enctype = "multipart/form-data" }))
                        { %>
                    <input type="file" name="uploadBudget" style=" width:300px" />
                    <input type="submit" value="提交" />
                    <%} %>
                </td>
            </tr>
        </table>
    </div>

    <div id="dialog-UploadReview" title="模板确认" style=" display:none; padding:20px">
            
        <span style=" font-size:large;">
        以下为本次上传的预算信息的检查结果。<br />
        请确认每项预算的处理方案和检查中发现的错误
        </span>
        <br />
        <br />
        <% List<TemplateSheetItem> Table = new List<TemplateSheetItem>();

            if (Session["Budget.Data.Review"] != null)
                Table = (List<TemplateSheetItem>)Session["Budget.Data.Review"];
            else if (ViewData["Budget.Data.Review"] != null)
                Table = (List<TemplateSheetItem>)ViewData["Budget.Data.Review"];
        %>

        <%if (Table.Count > 0) { %>
            <% int ErrorCount = 0; %>
            <table border="0" cellpadding="0" cellspacing="1" class="budget-table-no-01">
                <thead>
                <tr>
                    <td>编制单位</td>
                    <td>项目名称</td>
                    <td>项目负责人</td>
                    <td>是否垫支</td>
                    <td>垫支金额</td>
                    <td>预算金额</td>
                    <td>检查结果</td>
                    <td>处理方案</td>
                </tr>
                </thead>
                <tbody>
                <%  foreach (TemplateSheetItem Sheet in Table) 
                    {
                        Dictionary<String, ExcelSheetCellItem> Row = Sheet.BugetInfo;
                        if (!Sheet.IsOK)
                            ErrorCount++;
                %>
                <tr>
                    <td><%=Row["编制单位"].Text %></td>
                    <td><%=Row["项目名称"].Text %></td>
                    <td><%=Row["项目负责人"].Text %></td>
                    <td><%=Row["是否垫支"].Text%></td>
                    <td><%=Row["垫支金额"].Text %></td>
                    <td><%=Row["预算金额"].Text %></td>
                    <td><%=Row["检查结果"].Text %></td>
                    <td><%=Row["处理方案"].Text %></td>
                </tr>
                <% } %>
                </tbody>
            </table>

            <% if (ErrorCount == 0 && Session["Budget.Data.Review"] != null)
                { %>
                <% using (Html.BeginForm("DepartmentBudgetUpload_Submit", "Budget", FormMethod.Post))
                { %>
                    <br />
                    <input type="submit" value="确认提交" class="budget-button-no-01" onclick="Pending(true)" />
                <% } %>        
            <% }  %>
        <% } %>

    </div>

    <div id="dialog-Wait" style=" text-align:center; padding:0px; display:none; overflow:hidden">  
        <img src="../../Style/Img/loading-01.GIF" />
    </div>

</asp:Content>
